<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<%!
	public Map getMap(List<Map> result , Map<String,String> deptMap ){
		
		int sumCount = 0 ;
		//处理结合数据
		for(Map map : result){
			String ksdm = map.get("ksdm") == null ? "0" : map.get("ksdm").toString();
			map.put("deptName",deptMap.get(ksdm));
			sumCount++;
		}
		
		Map<String,Object> resMap = new HashMap<String,Object>();
		resMap.put("rank",result);
		resMap.put("sumCount",sumCount);
		return resMap;
	}
%>
<%
	//查询大费用
	String yydm =  input.getDesc("yydm","01");//医院代码	
	String ksdm = input.getDesc("ksdm","-1"); //传入科室代码代表该科室主任
	String date = input.getDesc("start_date","2018-01-06");//开始时间
	String endDa = input.getDesc("end_date","2018-12-24");//结束时间

	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
	String nowDate = sdf2.format(sdf.parse(date));
	String nowEndDa = sdf2.format(sdf.parse(endDa));
	
	String startDate = nowDate+"00:00:00";
	String endDate = nowEndDa+"23:59:59";

	String sqlWhere = " and js.jsrq > '"+ startDate + "' and js.jsrq < '" + endDate+"' " ;
	if(!yydm.equals("-1"))
	sqlWhere += " and js.ksdm in (select id  from his_dept where yydm ='"+yydm+"') " ;
	if(!"-1".equals(ksdm)){
		sqlWhere += " and js.ksdm in( " + ksdm + ")";
	}
	
	//获取所有科室
	List<Map> deptList = QBuilder.db("basedb").queryHql("select new map(id as id , name as name ) from his_dept ");
	Map<String,String> deptMap = new HashMap<String,String>();
	//科室放到map中 key-value(id-name)
	for(Map map : deptList){
		deptMap.put(map.get("id").toString(),map.get("name").toString());
	}
	
	
	//大费用病人明细

	
	
	List<Map> feelist = QBuilder.db("basedb").queryHql("select new map( js.syxh as syxh, js.zje as zje ,js.hzxm as hzxm , js.djrq as djrq , js.jsrq as jsrq , "
	+" js.ybdm as ybdm , js.memo as memo ) from ZY_BRJSK js  where js.jlzt in (0,2)  " + sqlWhere+ "  ");


	Map<String ,Object> zmMap = new HashMap<String ,Object>();
	String syxhids = "0";
	for(Map map : feelist ){
		double moneyTemp = Double.parseDouble(map.get("zje").toString());
		if(moneyTemp > 50000){
			zmMap.put(map.get("syxh").toString(),map);
			syxhids +=","+map.get("syxh").toString();
		}
	}
	//查到住院首页库明细
	String hql = "select new map ( a.syxh as syxh , a.blh as blh , a.cwdm as cwdm ,a.hzxm as hzxm , a.sex  as sex , a.ksdm as ksdm , a.bqdm as bqdm , a.zddm as zddm , a.ryrq as ryrq ,a.cyrq as cyrq ,  a.ssdm1 as ssdm1 ,a.ssdm2 as ssdm2 ,a.wzjb as wzjb  , a.memo as memo )"+
	" from ZY_BRSYK a where a.syxh in(" + syxhids+ "  )";
	List<Map> sylist = QBuilder.db("basedb").queryHql(hql);
	for(Map map : sylist){
		
		map.put("zje" , ((Map)zmMap.get(map.get("syxh").toString())).get("zje"));
	}


	Map<String,Object> ma1 = new HashMap<String,Object>();

	ma1.put("data",getMap(sylist , deptMap ));
	Message msg = new Message();

	msg.put("errcode",0);
	msg.put("big_charge",ma1);

	out.println(msg);
%>